using System;
using System.Collections.Generic;
using System.Reflection;


namespace foundation
{
    public class FuncInfo
    {
        public object target;
        public MethodInfo method;
    }

    public class FuncAttribute : Attribute
    {
        string name;
        public FuncAttribute(string name = null)
        {
            this.name = name;
        }
        public static Dictionary<string, FuncInfo> dict = new Dictionary<string, FuncInfo>();
        public static void register(BaseModel obj)
        {
            var t = obj.GetType();
            var methods = t.GetMethods();
            var AttributeType = typeof(FuncAttribute);
            foreach (var method in methods)
            {
                foreach (FuncAttribute attribute in method.GetCustomAttributes(AttributeType, true))
                {
                    var info = new FuncInfo();
                    info.target = method.IsStatic ? null : obj;
                    info.method = method;
                    dict.Add(null != attribute.name ? attribute.name : method.Name, info);
                }
            }
        }
    }
}